import pkg from '../package.json'
import { readdbs, writedbs } from  './db'
import { app, dialog } from 'electron'
// 获取项目信息
export const handleGetPro = (event, title) => {
    return  {
        name: pkg.name,
        version: pkg.version,
        description: pkg.description,
        author: pkg.author,
    }
}
// 读取数据
export const handleGetDatas = async (event, type) => {
    try{
        const res = await readdbs(type);
        return res;
    }catch(err){
        return err;
    }
}
// 保存数据
export const handleSetDatas = async (event, data, type) => {
    try{
        const res = await writedbs(data, type);
        return res;
    }catch(err){
        return err;
    }
}
// 设置开机自启
export const handleSetting = (event, autoStart) => {
    app.setLoginItemSettings({
        openAtLogin: autoStart,
        openAsHidden: false,
    })
}

// 获取文件存储路径
export const handleGetStorage = async(event) => {
    const res = await dialog.showOpenDialogSync({ properties: ['openDirectory'] });
    return res;
}